{
    title:  'Deploying a Site',
    crumbs: [ 
        { "User's Guide": "index.html" },
    ],
}
   
        <h1>Deploying a Site</h1>

        <p>When your site has been rendered, you can select just the files and directories that are 
        required for deployment to the live site. For security, it is recommended that you <em>not</em> 
        copy the entire development directory. Rather select only the files and directories that are actually
        required for the live site.</p>

        <h2>One Step Deploy</h2>

        <pre class="code">$ <b>expansive deploy</b></pre>

        <p>This copies the required files to the <em>./deploy</em> directory. You can also specify a deploy directory
        on the command line. For example:</p>

        <pre class="code">$ <b>expansive deploy /tmp/upload</b></pre>

        <p>This copies the required files to the <em>/tmp/upload</em> directory.</p>

    
        <h2>Files and Directories</h2>
        <p>These are the default files and directories that <em>expansive deploy</em> will deploy to the <em>./deploy</em>
        directory.</p>

        <table class="ui table" title="files">
            <thead>
                <tr><th>File/Directory</th><th>Contents</th></tr>
            </thead>
            <tbody>
                <tr>
                    <td>dist/</td>
                    <td>Public web content for the site.</td>
                </tr>
                <tr>
                    <td>package.json</td>
                    <td>The <em>package.json</em> file defines the ESP application name and version.</td>
                </tr>
            </tbody>
        </table>

        <h2>Customizing Deployment</h2>
        <p>The deploy command can be customized via the <em>control.deploy</em> property in the <em>expansive.json</em>
        file. For example:</p>

        <pre class="code">
{
    control: {
        deploy: {
            from: [
                "dist/**",
                "extra/*.pdf",
                "cache/*.dll",
                "cache/*.lib",
                "esp.json",
                "package.json"
            ],
            to: "deploy",
            clean: true,
            script: ''
        }
    }
}
</pre>
        <h3>Using <em>control.deploy</em> Properties</h3>
        <table class="ui table" title="properties">
            <thead>
                <tr><th>Property</th><th>Description</th></tr>
            </thead>
            <tbody>
                <tr><td>from</td><td>Array of source files. May contain wild-cards. Defaults to:
                    <em>['dist/**', 'cache/*', 'package.json', 'esp.json']</em>.</td></tr>
                <tr><td>flatten</td><td>Do not preserve source directory structure. Defaults to <em>false</em>.</td></tr>
                <tr><td>to</td><td>Destination directory. Defaults to <em>./deploy</em>.</td></tr>
                <tr><td>clean</td><td>Remove the prior contents of the destination directory.</td></tr>
                <tr><td>script</td><td>Script to run after copying any specified files.</td></tr>
            </tbody>
        </table>

        <h3>Remote Deployment</h3>
        <p>You can use the <em>deploy.script</em> property to upload to a remote server. This example below creates
        a compressed tar file of the deploy contents and then uses a HTTP <em>put</em> request to upload to a server.</p>

        <pre class="code">
{
  control: {
    deploy: {
      script: `
        require ejs.tar
        let file = Path('upload.tgz')
        Tar(file).create(Path('deploy').files('**', {directories: false}))
        let http = Http()
        http.put('http://example.com/' + file, file.readString())
        if (http.status != 200) {
            throw 'Cannot upload "' + file + '". Bad http status: ' + http.status  + '.'
        }
      `
    }
  }
}</pre>

